#include<iostream>
#include<algorithm>

using namespace std;

typedef long long LL;

const int N=5e5+10;

int n;
int l[N],r[N];
char s[N];


int main()
{
	cin>>n>>s;
	
	for(int i=0,h=0,g=0;i<n;i++){
		if(s[i]=='G') l[i]=h,h=0,g++;
		else l[i]=g,g=0,h++;
	}
	
	for(int i=n-1,h=0,g=0;i>=0;i--){
		if(s[i]=='G') r[i]=h,h=0,g++;
		else r[i]=g,g=0,h++;
	}
	
	LL sum=0;
	for(int i=0;i<n;i++){
		sum+=(LL)l[i]*r[i]+max(l[i]-1,0)+max(r[i]-1,0);
	}
	
	cout<<sum;
	return 0;
}
